~ chicken-core (master) /manual/Module (chicken bytevector)


  1[[tags: manual]]
  2[[toc:]]
  3
  4== Module (chicken bytevector)
  5
  6This module contains procedures for dealing with "bytevectors",
  7fixed-size sequences of unsigned 8-bit integers. Note that they are
  8indistinguishable from srfi-4 u8vectors and can be used
  9interchangeably. The R7RS literal expressions {{#u8(64 65 ...)}} can
 10also be used for construction. See [[Module (chicken number-vector)]].
 11
 12=== bytevector
 13
 14<procedure>(bytevector FIXNUM ...)</procedure>
 15
 16Returns a new bytevector containing the values {{FIXNUM ...}}.
 17
 18=== make-bytevector
 19
 20<procedure>(make-bytevector SIZE)</procedure>
 21
 22Returns a bytevector object of {{SIZE}} bytes, aligned on an 8-byte boundary,
 23uninitialized.
 24
 25=== bytevector?
 26
 27<procedure>(bytevector? X)</procedure>
 28
 29Returns {{#t}} if {{X}} is a bytevector object, or
 30{{#f}} otherwise.
 31
 32=== bytevector-length
 33
 34<procedure>(bytevector-length BYTEVECTOR)</procedure>
 35
 36Returns the number of bytes in {{BYTEVECTOR}}.
 37
 38=== bytevector-u8-ref
 39
 40<procedure>(bytevector-u8-ref BYTEVECTOR INDEX)</procedure>
 41
 42Returns the byte at {{INDEX}} in {{BYTEVECTOR}}.
 43
 44=== bytevector-u8-set!
 45
 46<procedure>(bytevector-u8-set! BYTEVECTOR INDEX VALUE)</procedure>
 47
 48Destructively modifies the byte at {{INDEX}} in {{BYTEVECTOR}} to {{VALUE}}, which
 49should be a fixnum.
 50
 51=== utf8->string
 52
 53<procedure>(utf8->string BYTEVECTOR [START END])</procedure>
 54
 55Returns a string with the contents of {{BYTEVECTOR}}. Invalid encodings
 56for characters signal an error.
 57
 58<procedure>(bytes->string BYTEVECTOR [START END])</procedure>
 59
 60Similar to {{utf8->string}}, but accepts any byte sequence without
 61validating the contents. Byte-sequences that are not representing
 62valid UTF-8 characters are retained and, if extracted with {{string-ref}}
 63are converted to a trailing surrogate pair half in the range U+DC80 to U+DCFF.
 64
 65=== string->utf8
 66
 67<procedure>(string->utf8 STRING)</procedure>
 68
 69Returns a bytevector with the contents of {{STRING}}.
 70
 71=== latin1->string
 72
 73<procedure>(latin1->string BYTEVECTOR)</procedure>
 74
 75Returns a string with the contents of {{BYTEVECTOR}} converted from Latin-1 (ISO-8859-1) encoding to UTF-8.
 76
 77=== string->latin1
 78
 79<procedure>(string->latin1 STRING)</procedure>
 80
 81Returns a bytevector with the contents of {{STRING}} encoded as Latin-1 (ISO-?8859-1).
 82
 83=== bytevector=?
 84
 85<procedure>(bytevector=? BYTEVECTOR1 BYTEVECTOR2)</procedure>
 86
 87Returns {{#t}} if the two argument bytevectors are of the same
 88size and have the same content.
 89
 90=== bytevector-append
 91
 92<procedure>(bytevector-append BYTEVECTOR ...)</procedure>
 93
 94Returns a new bytevector holding the concatenated contents of all
 95argument bytevectors.
 96
 97=== bytevector-copy
 98
 99<procedure>(bytevector-copy BYTEVECTOR #!optional START END)</procedure>
100
101Returns a new bytevector holding the contents of {{BYTEVECTOR}} between
102the indices {{START}} to {{END}}.
103
104=== bytevector-copy!
105
106<procedure>(bytevector-copy! TO AT FROM #!optional START END)</procedure>
107
108Copioes the contents of the bytevector FROM between
109the indices {{START}} to {{END}} into the bytevector {{TO}}, starting at
110index {{AT}}.
111
112
113---
114Previous: [[Module (chicken bitwise)]]
115
116Next: [[Module (chicken condition)]]
117
118
Trap